package com.zx.eval.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.zx.common.utils.PageUtils;
import com.zx.common.utils.Query;
import com.zx.eval.dao.ResultDao;
import com.zx.eval.entity.*;
import com.zx.eval.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;


@Service("ResultService")
public class ResultServiceImpl extends ServiceImpl<ResultDao, ResultEntity> implements ResultService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String memberName = (String)params.get("memberName");
        String tel = (String)params.get("tel");
        String company = (String)params.get("company");
        IPage<ResultEntity> page = this.page(
                new Query<ResultEntity>().getPage(params),
                new QueryWrapper<ResultEntity>()
                        .eq(!StringUtils.isEmpty(memberName), "member_name", memberName)
                        .eq(!StringUtils.isEmpty(tel), "phone", tel)
                        .like(!StringUtils.isEmpty(company), "company", company)
                        .orderByDesc("result_type")
                        .orderByDesc("id")
        );

        return new PageUtils(page);
    }

    @Override
    public boolean save(ResultEntity entity) {
        return super.save(entity);
    }

    @Autowired
    private QuestionService questionService;
}
